

#include "TextEntity.h"
#include "TextManager.h"
#include "Painter.h"

TextEntity::TextEntity(const std::string &_sText, const std::string &_sFontName, float _fFontSize, const Vector2 &_vPos, int _iHAlign, int _iVAlign, bool _bBreakLines, int _iLineWidth):
	RenderableEntity(new TextTexture(_sText, _sFontName, _fFontSize, _iHAlign, _iVAlign, _bBreakLines, _iLineWidth), _vPos)
{
    m_vSize = m_tTexture->getSize();
    m_bShadow = false;
    m_cShadowColor = COLOR_BLACK;
}

TextEntity::~TextEntity()
{
    if(m_tTexture != NULL)
	{
		free(m_tTexture);
		m_tTexture = NULL;
	}
}

void TextEntity::setText(const std::string &_sText)
{
	((TextTexture*) m_tTexture)->setText(_sText);
    m_vSize = m_tTexture->getSize();
}

void TextEntity::setShadow(bool _bShadow, Vector4 _cShadowColor)
{
    m_bShadow = _bShadow;
    m_cShadowColor = _cShadowColor;
}

void TextEntity::render()
{
	TextManager::instance().addText(this);
}

void TextEntity::renderTrue()
{
    if(m_bShadow)
        renderShadow(m_cShadowColor);
    
    RenderableEntity::render();
}

Vector2 TextEntity::getTextSize()
{
    return ((TextTexture*)m_tTexture)->getTextSize();
}
